﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows;
namespace Stock_App_V1
{
    public class NegativeValueConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string changePercentString && double.TryParse(changePercentString, out double changePercent))
            {
                return changePercent < 0 ? Brushes.Green : Brushes.Red;
            }
            return Brushes.Transparent;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class DiskComparisonConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            Console.WriteLine($"Values[0]: {values[0]}, Values[1]: {values[1]}, Values[2]: {values[2]}, Values[3]: {values[3]}");
            if (values[0] is string oDiskValueString && double.TryParse(oDiskValueString, out double oDiskValue) && values[1] is string iDiskValueString && double.TryParse(iDiskValueString, out double iDiskValue) && values[2] is Style negativeCellStyle && values[3] is Style positiveCellStyle)
            {
                if (oDiskValue > iDiskValue)
                {
                    return negativeCellStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property.Name == "Background")?.Value ?? Brushes.Transparent;
                }
                else if (oDiskValue < iDiskValue)
                {
                    return positiveCellStyle.Setters.OfType<Setter>().FirstOrDefault(x => x.Property.Name == "Background")?.Value ?? Brushes.Transparent;
                }
            }
            return Brushes.Transparent;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
